# 创建tuple
tuple1 = (1, 2, 3)
print(tuple1)  # (1, 2, 3)

tuple2 = (1)  # 一个元素这样写会被误解成数字
print(tuple2)  # 1
print(type(tuple2))  # <class 'int'>
tuple2 = (1,)  # 一个元素，加逗号
print(tuple2)  # (1,)
print(type(tuple2))  # <class 'tuple'>

tuple3 = tuple()  # tuple():类型转换
print(tuple3)
tuple5 = tuple('hello')
print(tuple5)  # ('h', 'e', 'l', 'l', 'o')
tuple5 = tuple([1,2,3])
print(tuple5)  # (1, 2, 3)

# 常用方法
tuple6 = (1, 2, 3, 'hello')
print(tuple6.count('h'))  # 0
print(tuple6.count('hello'))  # 1
print(tuple6.index('hello'))  # 3

# tuple iterating
for i in tuple6:
    print(i)

for i, j in enumerate(tuple6):
    print(i, j)

for i in range(len(tuple6)):
    print(i, tuple6[i])

